function pickSound(varargin)

% to play any sound:
%   there must be 4 dXsound objects.  This is true right after a task.  Or
%   you can do
%       rInit('debug')
%       rAdd('dXsound', 4);

% then edit three lines in this file
%   p = 1;%0.15;
%   fp=1%ceil(rand(1).*size(sounds,2))
%   rSet('dXtext', [9], 'string', fp);

% all sounds default to quarter volume
s = rGet('dXsound', 4, 'sound');
if ~isempty(s)
    rSet('dXsound', 4, 'gain', .25/max(abs(s(1:numel(s)))));
end

global ROOT_STRUCT
if ~isfield(ROOT_STRUCT, 'badTrialFlag') || ~ROOT_STRUCT.badTrialFlag

    % pick a new sound for this trial?
    p = 1;
    newSound=binornd(1, p, 1)

    if newSound==1
        %probability of getting a generic repeated sound
        genProb=0;
        genSound=binornd(1,genProb,1);

        if genSound==1
            rSet('dXsound', 4, 'rawSound', 'Pause.wav')
            fp=0
            %rPlay({'dXsound', 4})
        else

            %setup array of possible image files
            sounds={'1 up.wav', ...
                'Cannon Shot.wav', ...
                'Fireball.wav', ...
                'Mario Jump.wav', ...
                'Power Up.wav', ...
                'Super Mario 2 - Die.wav', ...
                'Super Mario 2 - Door.wav', ...
                'Super Mario 2 - Jump.wav',...
                'Super Mario 3 - Power Up.wav', ...
                'Super Mario 3 - Start Stage.wav', ...
                'Super Mario 2 - Lose Chance.wav',...
                'Super Mario 2 - Throw.wav', ...
                'Super Mario 2 - Game Over.wav', ...
                'Mario Jump.wav', ...
                'Super Mario 2 - Pick Up.wav',...
                'LOZ_Bomb_Drop.wav', ...
                'LOZ_Get_Item.wav', ...
                'LOZ_Get_Rupee.wav', ...
                'LOZ_Key.wav', ...
                'LOZ_Kill.wav', ...
                'LOZ_MagicalRod.wav', ...
                'AOL_Battle.wav', ...
                'AOL_Deflect.wav', ...
                'AOL_Elevator.wav', ...
                'AOL_Kill.wav', ...
                'AOL_LearnSpell.wav', ...
                'AOL_Map.wav', ...
                'AOL_Menu_Alphabet.wav', ...
                'AOL_Menu_Erase.wav', ...
                'AOL_Spell.wav', ...
                'AOL_Sword_Clang.wav', ...
                'AOL_Sword_Hit.wav', ...
                'AOL_Sword_Shoot.wav', ...
                };


            % pick a specific sound to play this trial
            fp=ceil(rand(1).*size(sounds,2))
            rSet('dXsound', 4, 'rawSound', sounds{fp});
        end

        % normalize all volumes by the max volume
        s = rGet('dXsound', 4, 'sound');
        rSet('dXsound', 4, 'gain', .5/max(abs(s(1:numel(s)))));

        rSet('dXtext', [5], 'string', fp);

    end
end

rPlay('dXsound', 4);